<div id="tb<?php echo $uniqid;?>" style="padding:5px">
    <table cellspacing="0" cellpadding="0">
        <tbody>
        <tr>
            <td><a href="javascript:;" onclick="autoordersEdit();" class="l-btn l-btn-small l-btn-plain"><span
                    class="l-btn-left l-btn-icon-left"><i class="iconfont icon-bianji"></i><span class="l-btn-text">查看</span></span></a></td>
            <td>
                <div class="datagrid-btn-separator"></div>
            </td>
            <td><a href="javascript:;" onclick="autoordersDelete();" class="l-btn l-btn-small l-btn-plain"><span
                    class="l-btn-left l-btn-icon-left"><i class="iconfont icon-shanchu"></i><span class="l-btn-text">删除</span></span></a></td>
            <td>
                <div class="datagrid-btn-separator"></div>
            </td>
            <td><a href="javascript:;" onclick="autoordersReload();" class="l-btn l-btn-small l-btn-plain"><span
                    class="l-btn-left l-btn-icon-left"><i class="iconfont icon-shuaxin"></i><span class="l-btn-text">重载</span></span></a></td>
            <td>&nbsp;&nbsp;<input id="autoordersKeywords" style="width:100px" type="text" class="easyui-input textbox"></td>
            <td><a href="javascript:void(0);" onclick="autoordersSearch();" class="l-btn l-btn-small l-btn-plain"><span
                    class="l-btn-left l-btn-icon-left"><i class="iconfont icon-sousuo"></i><span class="l-btn-text">查询</span></span></a></td>
        </tr>
        </tbody>
    </table>
</div>

<div class="con" onselectstart="return false;" style="-moz-user-select:none;">
    <table id="autoorders"></table>
</div>
<div id="iconlistdlg" class="easyui-dialog" style="width:720px; height:420px;" title="信息框" closed="true"></div>
<script>
    var autoordersView = function () {
        var row = $('#autoorders').treegrid('getSelected');
        if (row) {
            let title= '订单查看';
            let url = '/admin/autoorders/edit?id=' + row.id;
            $('#rightTabs').tabs('close', title);
            addTab(title, url);
        } else {
            $.messager.alert('提示', '请先选择要编辑的行！', 'warning');
        }
    };
    var autoordersDelete = function () {
        var row = $('#autoorders').treegrid('getSelected');
        if (row) {
            $.messager.confirm('提示', '确定删除吗？', function (r) {
                if (r == true) {
                    $.messager.progress();
                    $.post('/admin/autoorders/delete', {id: row.id}, function (data) {
                        $.messager.progress('close');
                        if (data.ret == 0) {
                            $.messager.show({
                                title: '提示',
                                msg: data.msg,
                                timeout: 3000,
                                showType: 'slide'
                            });
                            autoordersReload();
                        } else {
                            $.messager.alert('提示', data.msg, 'warning');
                        }
                    }, 'json');
                }
            });
        } else {
            $.messager.alert('提示', '请先选择要删除的行！', 'warning');
        }
    };
    var autoordersReload = function () {
        $("#autoorders").treegrid('reload');
    };
    var autoordersSearch = function () {
        var height = $(window).height() - $(".top").height() - 46;
        var width = $(window).width() - $(".leftmenu").width() - 13;
        $("#autoorders").treegrid({
            title: '预约订单',
            width: width,
            height: height,//高度
            singleSelect: true,//如果为true，则只允许选择一行
            striped: true,//是否显示斑马线效果。
            rownumbers: true,//如果为true，则显示一个行号列。
            pagination: true,//是否显示分页
            pageSize: 10,
            pageList: [10, 15, 20, 25],
            method: 'post',
            sortName: 'created_at',
            sortOrder: 'desc',
            idField: 'id',
            treeField: 'name',
            url: '/admin/autoorders/get',
            queryParams: {keywords: $('#autoorderskeywords').val()},
            fitColumns: true,//真正的自动展开/收缩列的大小，以适应网格的宽度，防止水平滚动。
            nowrap: true,//如果为true，则在同一行中显示数据。设置为true可以提高加载性能。 是否换行
            selectOnCheck: true,
            checkOnSelect: true,
            toolbar: '#tb<?php echo $uniqid;?>',
            columns: [[
                {field: 'order_no', title: '订单编号', width: '10%'},
                {field: 'company', title: '车检站', width: '10%', align:'center', formatter:function(value, rowData, rowIndex) {
                        return rowData.company.name;
                    }},
                {field: 'customer', title: '客户', width: '5%', align:'center', formatter:function(value, rowData, rowIndex) {
                        return rowData.customer.username;
                    }},
                {field: 'car_no', title: '车牌号', width: '5%'},
                {field: 'car_type', title: '车型', width: '5%'},
                {field: 'car_seat', title: '车座', width: '5%'},
                {field: 'phone', title: '联系电话', width: '7%'},
                {field: 'contact', title: '联系人', width: '5%'},
                {field: 'arrival_date', title: '到站日期', width: '5%'},
                {field: 'timeslot', title: '时间段', width: '5%', align:'center', formatter:function(value, rowData, rowIndex) {
                        return rowData.timeslot.slot;
                    }},
                {field: 'status_name', title: '订单状态', width: '5%'},
                {field: 'paid_at', title: '支付日期', width: '8%'},
                {field: 'created_at', title: '创建时间', width: '8%'},
            ]],
            onDblClickRow: function (index, field) {
                autoordersView();
            },
            onLoadSuccess: function (row, data) {
                $.each(data, function (i, val) {
                    //$('#autoorders').treegrid('collapseAll', data[i].id)
                })
            }
        });
    };
    autoordersSearch();
</script>
